import 'package:dk_flutter_base/src/ui/ui_model/select_model.dart';
import 'package:dk_flutter_base/src/ui/widget/dk_app_bar.dart';
import 'package:dk_flutter_base/src/ui/widget/dk_bottom_dialog.dart';
import 'package:dk_flutter_base/src/ui/widget/dk_bottom_sheet_dialog.dart';
import 'package:dk_flutter_base/src/ui/widget/dk_widget_container.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import 'package:dk_flutter_base/src/ui/widget/trans_select_bottom.dart';

class Person with SelectModel {
  String title;
  String content;

  Person(this.title, this.content) {
    initSelectModel(title, content);
  }
}

class BottomSheetWidget extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return BottomSheetSate();
  }
}

class BottomSheetSate extends State<BottomSheetWidget> {
  final List<Person> list = List();

  @override
  void initState() {
    super.initState();
    for (int i = 0; i < 3; i++) {
      list.add(Person('标题$i', '内容$i'));
    }
  }

  String btn = "底部弹窗";
  final TransSelectBottomOption transSelectBottomOption =
      TransSelectBottomOption();

  @override
  Widget build(BuildContext context) {
    var listView = ListView.builder(
      itemCount: list.length,
      itemBuilder: (context, index) {
        return Container(
          height: 80,
          child: Text(list[index].title),
        );
      },
    );
    return Scaffold(
      appBar: AppBar(
        elevation: 0.0,
        title: Text('弹窗'),
      ),
      body: Container(
        color: Colors.red,
        height: double.infinity,
        child: InkWell(
          child: Text(btn),
          onTap: () {
            DkBottomDialog.create(
                BottomDialogOption((BuildContext context) {
              return TransSelectBottom(
                list,
                transSelectBottomOption,
              );
            }, handleResult: (SelectModel value) {
              if (null != value) {
                print("value============" + value.value);
              }
            })).show(context);
//            showDialog(
//              barrierDismissible: true,
//                context: context,
//                builder: (BuildContext context) {
//                  return Material(
//                    color: Colors.transparent,
//                    child: Column(
//                      mainAxisSize: MainAxisSize.max,
//                      children: <Widget>[
//                        Expanded(
//                          flex: 1,
//                          child: InkWell(
//                            onTap: () {
//                              setState(() {
//                                Navigator.of(context).pop();
//                                btn = "被改变了";
//                              });
//                            },
//                            child: Container(),
//                          ),
//                        ),
//                        TransSelectBottom(
//                          list,
//                          transSelectBottomOption,
//                        ),
//                      ],
//                    ),
//                  );
//                }).then((value) {
//              print("value============" + (value==null).toString());
//            });

            /*DkBottomSheetDialog.create(BottomSheetOption.withWidget(
                  context, listView,
                  containerParam: ContainerParam.withDefault(height: 100)))
              .show();*/
//            DkBottomSheetDialog.create(
//              BottomSheetOption.withSheetPageWidget(
//                context,
//                TransSelectBottom(
//                  list,
//                  transSelectBottomOption,
//                ),
//                containerParam: ContainerParam.withDefault(
//                  height: transSelectBottomOption.getTotalHeight(list.length),
//                ),
//                handleResult: (SelectModel value) {
//                  setState(() {
//                    btn = "被改变了";
//                    print("key---------"+value.key);
//                    print("value---------"+value.value);
//                  });
//                },
//              ),
//            ).show();
          },
        ),
      ),
    );
  }

/*void showSheet(BuildContext context, Widget listView) {
    showBottomSheet(
      context: context,
      builder: (BuildContext context) {
        return Container(
          child: listView,
          height: 300,
        );
      },
    );
  }

  void showSheetPage(BuildContext context, ListView listView) {
    showModalBottomSheet(
        context: context,
        builder: (BuildContext context) {
          Container(
            child: listView,
            height: 300,
          );
        });
  }*/
}
